package cn.thoughtworks.school.repositories;

import cn.thoughtworks.school.entities.HomeworkQuiz;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface HomeworkQuizRepository extends JpaRepository<HomeworkQuiz, Long>,JpaSpecificationExecutor<HomeworkQuiz> {
    List<HomeworkQuiz> findByIdInAndIsAvailableIsTrue(List<Long> ids);

    @Query(value = "SELECT  b FROM HomeworkQuiz b JOIN b.tags t WHERE  b.isAvailable=true AND t.name in :names")
    List<HomeworkQuiz> findHomeworkQuizzesByTags(@Param("names") List<String> names);

    List<HomeworkQuiz> findByIdIn(List<Long> ids);

}
